﻿@model ScmSafetyassessmentViewModel
@{
    Layout = null;
    ViewBag.Title = "安全考核分项得分上报";
}
<script type="text/javascript">
    function FormSubmit() {
        var count = @Model.TheAssessmentscoreList.Count;
        var all=0;
        var score=0;
        var allsum=0;
        var scoresum=0;
        for(var i=0;i<count;i++)
        {
            score=$("#TheAssessmentscoreList_" + i + "__As_Score").val();
            all=$("#TheAssessmentscoreList_" + i + "__Ai_AllScore").val();
            if(score!="")
            {
                scoresum=parseInt(scoresum)+ parseInt(score);
                allsum=parseInt(allsum)+parseInt(all);
            }
        }
        if(allsum!=0)
        {
            var val= (scoresum/allsum)*100;
            val=Math.round(val*100)/100;
            $("#TheAssessmentunitList_" +@ViewBag.Index +"__Au_Score").val(val);
        }
        $("#Form_ItemReport").submit();
    }
    function Deduct(i) {
        var reg = new RegExp("^[0-9]*$");
        var all = $("#TheAssessmentscoreList_" + i + "__Ai_AllScore").val();
        var de = $("#TheAssessmentscoreList_" + i + "__As_Deduct").val();
        var sc = $("#TheAssessmentscoreList_" + i + "__As_Score").val();
        if (de != "") {
            if (reg.test(de)) {
                var val = all - de;
                if (val < 0) {
                    alert("扣分不能大于总分！");
                    if (sc !== "")
                        $("#TheAssessmentscoreList_" + i + "__As_Deduct").val(all - sc);
                    else
                        $("#TheAssessmentscoreList_" + i + "__As_Deduct").val("");
                } else {
                    $("#TheAssessmentscoreList_" + i + "__As_Score").val(all - de);
                }
            } else {
                if (sc !== "")
                    $("#TheAssessmentscoreList_" + i + "__As_Deduct").val(all - sc);
                else
                    $("#TheAssessmentscoreList_" + i + "__As_Deduct").val("");
            }
        }
        $("#TheAssessmentscoreList_" + i + "__As_Deduct").focus();
    }
    function Score(i) {
        var reg = new RegExp("^[0-9]*$");
        var all = $("#TheAssessmentscoreList_" + i + "__Ai_AllScore").val();
        var de = $("#TheAssessmentscoreList_" + i + "__As_Deduct").val();
        var sc = $("#TheAssessmentscoreList_" + i + "__As_Score").val();
        if (sc != "") {
            if (reg.test(sc)) {
                var val = all - sc;
                if (val < 0) {
                    alert("得分不能大于总分！");
                    if (de != "")
                        $("#TheAssessmentscoreList_" + i + "__As_Score").val(all - de);
                    else
                        $("#TheAssessmentscoreList_" + i + "__As_Score").val("");
                } else {
                    $("#TheAssessmentscoreList_" + i + "__As_Deduct").val(all - sc);
                }
            } else {
                if (de != "")
                    $("#TheAssessmentscoreList_" + i + "__As_Score").val(all - de);
                else
                    $("#TheAssessmentscoreList_" + i + "__As_Score").val("");
            }
        }
        $("#TheAssessmentscoreList_" + i + "__As_Score").focus();
    }
    function delItemTr(i) {
        var title = $("#a_TheAssessmentscoreList_"+i).attr("title");
        if (title == "添加该考核项") {
            $("#TheAssessmentscoreList_" + i + "__As_UnitInclude").val("True");
            $("#TheAssessmentscoreList_" + i + "__As_Deduct").attr("disabled",false);
            $("#TheAssessmentscoreList_" + i + "__As_Score").attr("disabled",false);
            $("#TheAssessmentscoreList_" + i + "__As_DeductReason").attr("disabled",false);
            $("#TheAssessmentscoreList_" + i + "__As_Deduct").attr("class","digits textInput valid");
            $("#TheAssessmentscoreList_" + i + "__As_Score").attr("class","digits textInput valid");
            $("#TheAssessmentscoreList_" + i + "__As_DeductReason").attr("class","textInput");
            $("#a_TheAssessmentscoreList_"+i).attr("title", "排除该考核项");
            $("#a_TheAssessmentscoreList_"+i).attr("class", "btnSelect");
            $("#tr_TheAssessmentscoreList_"+i).attr("style", "");
        }
        else {
            $("#TheAssessmentscoreList_" + i + "__As_UnitInclude").val("False");
            $("#TheAssessmentscoreList_" + i + "__As_Deduct").val("");
            $("#TheAssessmentscoreList_" + i + "__As_Score").val("");
            $("#TheAssessmentscoreList_" + i + "__As_DeductReason").val("");
            $("#TheAssessmentscoreList_" + i + "__As_Deduct").attr("disabled",true);
            $("#TheAssessmentscoreList_" + i + "__As_Score").attr("disabled",true);
            $("#TheAssessmentscoreList_" + i + "__As_DeductReason").attr("disabled",true);
            $("#TheAssessmentscoreList_" + i + "__As_Deduct").attr("class","digits textInput valid disabled");
            $("#TheAssessmentscoreList_" + i + "__As_Score").attr("class","digits textInput valid disabled");
            $("#TheAssessmentscoreList_" + i + "__As_DeductReason").attr("class","textInput disabled");
            $("#a_TheAssessmentscoreList_"+i).attr("title", "添加该考核项");
            $("#a_TheAssessmentscoreList_"+i).attr("class", "btnDel");
            $("#tr_TheAssessmentscoreList_"+i).attr("style", "color: #808080");
        }
    }
</script>
<form id="Form_ItemReport" method="post" action="@Url.Action("SafeAssessmentItemReport", "ScmSafeAssessment")" class="pageForm required-validate" onsubmit="return validateCallback(this,dialogAjaxDone)">
    <div style="float: left; display: block; margin: 10px; overflow: auto; width: 900px; height: 400px; border: solid 1px #CCC; line-height: 21px; background: #FFF; text-align: center;">
        <table class="table" width="100%" layouth="140" nowraptd="false">
            <thead>
                <tr>
                    <th width="30">序号</th>
                    <th>类别</th>
                    <th>考核项目</th>
                    <th width="40">总分</th>
                    <th width="100">扣分</th>
                    <th width="100">得分</th>
                    <th>扣分原因</th>
                    <th width="30">操作</th>
                </tr>
            </thead>
            <tbody>
                @for (int index = 0; index < Model.TheAssessmentscoreList.Count; index++)
                {
                    string trid = "tr_TheAssessmentscoreList_" + index;
                    string aid = "a_TheAssessmentscoreList_" + index;
                    if (Model.TheAssessmentscoreList[index].As_UnitInclude)
                    {
                    <tr id="@trid">
                        <td>@Model.TheAssessmentscoreList[index].Ai_Order</td>
                        <td>@Model.TheAssessmentscoreList[index].Scd_Name</td>
                        <td>@Model.TheAssessmentscoreList[index].Ai_Project</td>
                        <td>@Model.TheAssessmentscoreList[index].Ai_AllScore</td>
                        <td>
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].Sa_ID, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].Ai_ID, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].Au_ID, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_Include, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_UnitInclude, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].Ai_AllScore, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_Deduct, new { @class = "digits textInput valid", @size = "8", @onkeyup = "Deduct(" + index + ")" })
                        </td>
                        <td>
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_Score, new { @class = "digits textInput valid", @size = "8", @onkeyup = "Score(" + index + ")" })
                        </td>
                        <td>
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_DeductReason, new { @size = "18" })
                        </td>
                        <td>
                            <a title="排除该考核项" id="@aid" href="javascript:delItemTr('@index')" class="btnSelect">排除</a>
                        </td>
                    </tr>
                    }
                    else
                    {
                    <tr id="@trid" style="color: #808080">
                        <td>@Model.TheAssessmentscoreList[index].Ai_Order</td>
                        <td>@Model.TheAssessmentscoreList[index].Scd_Name</td>
                        <td>@Model.TheAssessmentscoreList[index].Ai_Project</td>
                        <td>@Model.TheAssessmentscoreList[index].Ai_AllScore</td>
                        <td>
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].Sa_ID, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].Ai_ID, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].Au_ID, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_Include, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_UnitInclude, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].Ai_AllScore, new { @type = "hidden" })
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_Deduct, new { @class = "digits textInput valid", @size = "8", @onkeyup = "Deduct(" + index + ")", @disabled = "true" })
                        </td>
                        <td>
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_Score, new { @class = "digits textInput valid", @size = "8", @onkeyup = "Score(" + index + ")", @disabled = "true" })
                        </td>
                        <td>
                            @Html.TextBoxFor(m => m.TheAssessmentscoreList[index].As_DeductReason, new { @size = "18", @disabled = "true" })
                        </td>
                        <td>
                            <a title="添加该考核项" id="@aid" href="javascript:delItemTr('@index')" class="btnDel">添加</a>
                        </td>
                    </tr> 
                    }
                }
            </tbody>
        </table>
        <div class="pageFormContent">
            <dl>
                <dt>附件：</dt>
                <dd>
                   <input id="AssistID" name="AssistID" value="@ViewBag.AssisId" type="hidden"/>

                        <a href='/Common/UploaderFile/Uploader/?id=ZDFileID' width="710" height="460" rel="rel_WorkFlow_WorksMeasure_Attach" mask="true" target="dialog" title="附件管理">
                                    <img src="/Content/themes/default/images/fj.gif" alt="查看附件" id='ZDFileID' 
                                   uploaderoption="{MoudleID:@ViewBag.MoudleID,'ToSelectIDs':[@ViewBag.FileIds],'ToDeleteIDs':[@ViewBag.DeleteIds],BizDeleteURL:'/SafetyConstruction/Base/Delete/',BizSaveUrl:'/SafetyConstruction/Base/BatchAdd/',BizType:'SafeAssessment_Rules',BizID:'@ViewBag.AssisId','dirWhere':'@ViewBag.DirWhere'}" />
                                </a>
                </dd>
            </dl>
        </div>
    </div>
    <div class="formBar">
        <ul>
            <li>
                <button type="button" class="btn btn-sm" onclick="FormSubmit()">保存</button>
            </li>
            <li>
                <button type="button" class="close btn btn-default btn-sm">取消</button>
            </li>
        </ul>
    </div>
</form>


